from object import Object
import sys

class OptionServer(Object):
    def __init__(self):
        Object.__init__(self)
        
        self.load("options.yml")
        
        for i,tok in enumerate(sys.argv):
            if tok[0] == '+':
                self.setVar(tok[1:],True)
            elif tok[0] == '-':
                self.setVar(tok[1:],False)
            elif tok == '=' and i > 0 and i < len(sys.argv)-1:
                self.setVar(sys.argv[i-1],self.fixVal(sys.argv[i+1]))
            elif '=' in tok:
                pos = tok.find('=')
                self.setVar(tok[:pos],self.fixVal(tok[pos+1:]))
                
        if self.vars:
            print "options:", self.vars

    def fixVal(self, val):
        try:
            return eval(val)
        except:
            return val
